<template>
  <a-row :gutter="24" class="search-row">
    <a-col :span="24">
      <x-card>
        <div slot="content" class="table-page-search-wrapper" ref="myElement">
          <a-form layout="inline">
            <a-row :gutter="24">
              <a-col :span="24">
                <a-form-item style="margin-bottom: 20px; margin-top: -30px">
                  <a-divider orientation="left" style="font-weight: bold">
                    <a-icon type="profile" style="margin-right: 8px;color:rgb(13, 158, 243);"></a-icon>基本信息
                  </a-divider>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="数据来源"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择数据来源"
                    v-model="selectedCheckTypes"
                    mode="multiple"
                    @change="handleCheckTypeChange"
                    style="height: 40px; overflow-y: auto;">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option v-for="item in CheckTypeList" :key="item.id" :value="item.item">{{
                      item.item
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="检查人员"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-input allow-clear v-model="queryParam.UserName" placeholder="请输入姓名" />
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item
                  label="检查时间"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-date-picker style="width: 100%" format="YYYY-MM-DD" @change="onChange1" :style="{width: '50%'}" v-model="TimeOn"/>
                  <a-date-picker style="width: 100%" format="YYYY-MM-DD" @change="onChange2" :style="{width: '50%'}" v-model="TimeEnd"/>
                </a-form-item>
              </a-col>
              <a-col :span="2" class="search-buttons">
                <a-button type="primary" @click="handleClick" v-if="hasPerm('hdv_qhse_v_compage')">查询</a-button>
              </a-col>
              <a-col :span="2" class="search-buttons">
                <a-button style="margin-left: 8px" @click="reset">重置</a-button>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="6">
                <a-form-item
                  label="违章单位"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-tree-select
                    :style="{ width: selectWidth + 'px' }"
                    allowClear
                    showSearch
                    style="scroll:true"
                    tree-node-filter-prop="title"
                    v-model="queryParam.OrganizationName"
                    :treeData="QHSEOrganizationTree"
                    v-if="QHSEOrganizationTree.length"
                    @change="handleOrganizationSelectChange"
                    :defaultExpandAll="true"
                    :defaultExpandedKeys="defaultExpandedKeys"
                    :replaceFields="replaceFields"
                    ref="tree"
                    placeholder="请选择违章单位"
                    :title="queryParam.OrganizationName" />
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="检查单位"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-tree-select
                    :style="{ width: selectWidth + 'px' }"
                    allowClear
                    showSearch
                    style="scroll:true"
                    tree-node-filter-prop="title"
                    v-model="queryParam.CheckOrganizationName"
                    :treeData="QHSEOrganizationTree1"
                    v-if="QHSEOrganizationTree1.length"
                    @change="onChangeCheckData"
                    :defaultExpandAll="true"
                    :defaultExpandedKeys="defaultExpandedKeys"
                    :replaceFields="replaceFields"
                    ref="tree"
                    placeholder="请选择检查单位"
                    :title="queryParam.CheckOrganizationName"/>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item label="违章人员" :labelCol="{ style: 'width:115px' }">
                  <a-input
                    suffix-icon="down"
                    v-model="UserName"
                    @click="showModals"
                    allow-clear
                    placeholder="请选择违章人员姓名"/>
                  <a-modal
                    @cancel="handleCancel"
                    :visible="visible"
                    :width="1400"
                    :height="2000"
                  >
                    <choose-people
                      :people-list="peopleList"
                      @cancel="handleCancel"
                      @chooseUser="chooseVioPeople"
                      :userId="queryParam.UserId"
                    />
                    <template #footer>
                      <a-button type="default" @click="handleCancel">取消</a-button>
                    </template>
                  </a-modal>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="数据录入来源"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    :style="{ width: selectWidth + 'px' }"
                    allow-clear
                    placeholder="请选择数据录入来源"
                    v-model="selectedCheckTypes1"
                    mode="multiple"
                    @change="handleCheckTypeChange1"
                    style="height: 40px; overflow-y: auto;">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option v-for="item in enterSyslist" :key="item.id" :value="item.item">{{ item.item }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-divider orientation="left" style="font-weight: bold; margin-top: -20px;">
              <a-icon type="info-circle" style="margin-right: 8px;color:rgb(13, 158, 243);"></a-icon> 关键作业信息
            </a-divider>
            <a-row :gutter="24">
              <a-col :span="6">
                <a-form-item
                  label="作业专业"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择作业专业"
                    style="height: 40px; overflow-y: auto;"
                    v-model="selectedWorkSpecialty"
                    @change="handleZYZYSelectChange"
                    mode="multiple"
                    :max-tag-count="7">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option v-for="item in QHSEKeyWorkSpecialtyList" :key="item.id" :value="item.specialty" :code="item.specialtyCode">{{
                      item.specialty
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="关键作业类型"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择关键作业类型"
                    style="height: 40px; overflow-y: auto;"
                    v-model="selectedWorkType"
                    @change="handleKeyWorkTypeSelectChange"
                    mode="multiple"
                    :max-tag-count="7">
                    <a-select-option value="全部" v-if="selectedWorkSpecialty && selectedWorkSpecialty.length !== 0">全部</a-select-option>
                    <a-select-option v-for="item in KeyWorkTypeList" :key="item.id" :value="item.workType">{{
                      item.workType
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="作业风险等级"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    v-model="selectedRisk"
                    allow-clear
                    placeholder="请选择作业风险等级"
                    @change="handleRiskSelectChange"
                    mode="multiple"
                    style="height: 40px; overflow-y: auto;">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option v-for="item in RiskList" :key="item.id" :value="item.item">{{
                      item.item
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="位置区域"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    v-model="selectedLocation"
                    allow-clear
                    placeholder="请选择位置区域"
                    style="height: 40px; overflow-y: auto;"
                    @change="handleLocationSelectChange"
                    mode="multiple"
                    :max-tag-count="6">
                    <a-select-option value="全部" v-if="selectedWorkSpecialty && selectedWorkSpecialty.length !== 0">全部</a-select-option>
                    <a-select-option v-for="item in LocationList" :key="item.id" :value="item.location">{{
                      item.location
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="48">
            </a-row>
            <a-divider orientation="left" style="font-weight: bold; margin-top: -10px;">
              <a-icon type="user" style="margin-right: 8px;color:rgb(13, 158, 243);"></a-icon> 违章人员
            </a-divider>
            <a-row :gutter="24">
              <a-col :span="6">
                <a-form-item
                  label="年龄"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择年龄"
                    mode="multiple"
                    v-model="selectedAge"
                    @change="handleAgeChange"
                    style="height: 40px; overflow-y: auto;">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option v-for="item in QHSEAgeList" :key="item.id" :value="item.item">{{
                      item.item
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="违章岗位"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择违章岗位"
                    style="height: 40px; overflow-y: auto;"
                    v-model="selectedPosition"
                    @change="handlePositionSelectChange"
                    mode="multiple"
                    :max-tag-count="7">
                    <a-select-option value="全部" v-if="selectedWorkSpecialty && selectedWorkSpecialty.length !== 0">全部</a-select-option>
                    <a-select-option v-for="item in PositionList" :key="item.id" :value="item.position">{{
                      item.position
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="用工性质"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择用工性质"
                    v-model="selectedEmployeeType"
                    @change="handleEmployeeTypeSelectChange"
                    mode="multiple"
                    style="height: 40px; overflow-y: auto;">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option v-for="item in QHSEYGXZList" :key="item.id" :value="item.item">{{
                      item.item
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="工龄"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择工龄"
                    v-model="selectedWorkYears"
                    @change="handleWorkYearsSelectChange"
                    mode="multiple"
                    style="height: 40px; overflow-y: auto;">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option v-for="item in QHSEGLList" :key="item.id" :value="item.item">{{
                      item.item
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="48">
            </a-row>
            <a-divider orientation="left" style="font-weight: bold; margin-top: -10px;">
              <a-icon type="exclamation-circle" style="margin-right: 8px;color:rgb(13, 158, 243);"></a-icon> 违章信息
            </a-divider>
            <a-row :gutter="24">
              <a-col :span="6">
                <a-form-item
                  label="违章性质"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select
                    allow-clear
                    placeholder="请选择违章性质"
                    v-model="selectedViolationType"
                    @change="handlViolationTypeSelectChange"
                    mode="multiple"
                    style="height: 40px; overflow-y: auto;">
                    <a-select-option value="全部">全部</a-select-option>
                    <a-select-option
                      v-for="item in ViolationTypeList"
                      :key="item.violationTypeId"
                      :value="item.violationType">{{
                        item.violationType
                      }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="违章类别"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-tree-select
                    :style="{ width: selectWidth + 'px' }"
                    v-model="queryParam.violationCategory"
                    allowClear
                    showSearch
                    style="scroll: true"
                    tree-node-filter-prop="title"
                    v-if="QHSEViolationCategoryLBTree.length"
                    :treeData="QHSEViolationCategoryLBTree"
                    :defaultExpandAll="true"
                    :replaceFields="replaceFields"
                    @change="handleViolationCategorySelectChange"
                    placeholder="请选择违章类别"
                    :title="queryParam.violationCategory"
                  >
                  </a-tree-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="记分"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select allow-clear v-model="queryParam.scoreSymbol" class="smallSelect">
                    <a-select-option value=">"> ></a-select-option>
                    <a-select-option value=">="> >=</a-select-option>
                    <a-select-option value="="> =</a-select-option>
                    <a-select-option value="<="> &lt;=</a-select-option>
                    <a-select-option value="<"> &lt;</a-select-option>
                  </a-select>
                  <a-input allow-clear placeholder="请输入记分分数" v-model="score" class="midSelect"/>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  label="罚款"
                  :labelCol="{ style: 'width:115px' }"
                  :wrapperCol="wrapperCol"
                >
                  <a-select allow-clear v-model="queryParam.fineSymbol" class="smallSelect" >
                    <a-select-option value=">"> ></a-select-option>
                    <a-select-option value=">="> >=</a-select-option>
                    <a-select-option value="="> =</a-select-option>
                    <a-select-option value="<="> &lt;=</a-select-option>
                    <a-select-option value="<"> &lt;</a-select-option>
                  </a-select>
                  <a-input allow-clear placeholder="请输入罚款" v-model="fine" class="midSelect"/>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item label="检查方式" :labelCol="{ style: 'width:115px' }">
                  <a-select allow-clear placeholder="请选择检查方式" v-model="queryParam.InspectionMethod">
                    <a-select-option v-for="item in dangerCheckData" :key="item.id" :value="item.item">{{ item.item }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item label="是否重复性违章" style="margin-left: 25px;">
                  <a-checkbox-group v-model="queryParam.timesViolation" style="margin-left: 10px;">
                    <a-checkbox value="1" style="margin-left: 10px">是</a-checkbox>
                    <a-checkbox value="0" style="margin-left: 10px">否</a-checkbox>
                  </a-checkbox-group>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
      </x-card>
      <a-card :bordered="false">
        <a-col :span="2" class="search-buttons" style="margin-left: 5px;">
          <a-button type="primary" @click="handleExport" :loading="batchExportLoading"><a-icon type="export"/>导出</a-button>
        </a-col>
        <a-col :span="4">
          <a-progress
            v-if="batchExportLoading"
            :percent="exportProgress"
            status="active"
          />
        </a-col>
        <a-col :span="2" class="search-buttons" style="margin-left: 5px;">
          <a-switch @click="handleChangeStatus"></a-switch>
        </a-col>
        <s-table
          ref="table"
          :columns="columns"
          :data="loadData"
          :alert="null"
          :rowKey="(record) => record.qhseXyViolationId"
          :rowSelection="null"
          bordered
          style="margin-top: 20px"
        >
          <span slot="action" slot-scope="text, record">
            <a-button size="small" style="color:#389e0d;background-color: #f6ffed;border-color: #b7eb8f;">
              <a @click="$refs.VioDetail.edit(record)">
                <a-icon type="file-text" />
                详情
              </a>
            </a-button>
            <a-button size="small" style="color: #1d39c4;background-color: #f0f5ff;border-color: #adc6ff;" v-show="hasPerm('company_violation_send')">
              <a @click="handleSend(record)">
                <a-icon type="lock" />
                推送
              </a>
            </a-button>
          </span>
        </s-table>
        <vio-detail ref="VioDetail" @ok="handleOk" />
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
import Vue from 'vue'
import { STable, XCard, XDown, VioDetail } from '@/components'
import { Empty } from 'ant-design-vue'
import { getQHSEComPage, getQHSEXyViolationTypeList, getDownloadExcel, getDataPush } from '@/api/modular/system/QHSEXyViolation'
import { getDangerCheckType } from '@/api/modular/system/QHSEDangerinsertManager'
import { getQHSEOrganizationTree, getQHSELocationPage, getQHSEPositionPage } from '@/api/modular/system/QHSEOrganization'
import { getQHSEKeyWorkSpecialtyList, getQHSEKeyWorkTypePage } from '@/api/modular/system/QHSEKeyWork'
import { getQHSEViolationCategoryLBTree } from '@/api/modular/system/QHSEViolationCategory'
import {
  getQHSEAgeList,
  getQHSEGLList,
  getQHSEYGXZList,
  getCheckTypeList,
  getRiskList
} from '@/api/modular/system/QHSEDictionary'
import { getQHSEEnterSysList } from '@/api/modular/system/QHSEHazardQuery'
import moment from 'moment'
import { ChoosePeople } from '@/components/index'
import { getQHSETimerTimersClose, getQHSETimerTimersStart } from '@/api/modular/system/QHSESetTimroutManager'
import { mapGetters } from 'vuex'
export default {
  components: {
    XDown,
    XCard,
    STable,
    VioDetail,
    ChoosePeople
  },
  data() {
    return {
      selectWidth: 200,
      peopleList: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      secondOraName: {
          id: ''
        },
      // 查询参数
      queryParam: {
        TimeOn: moment(new Date()).subtract(1, 'months').format('YYYY-MM-DD'),
        TimeEnd: moment(new Date()).format('YYYY-MM-DD') + 'T' + moment().format('23:59:59'),
        OrganizationId: '',
        CheckOrganizationId: ''
      },
      // 导出参数
      exportParam: {},
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => `${index + 1}`
        },
        {
          title: '检查时间',
          dataIndex: 'checkDate',
          customRender: (text, record) => {
            if (record.checkDate) {
              const dateParts = record.checkDate.split('T')[0].split('-')
              return `${dateParts[0]}-${dateParts[1]}-${dateParts[2]}`
            }
            return ''
          }
        },
        {
          title: '检查单位',
          dataIndex: 'checkOrganizationName',
          width: 200,
          customRender: (text) => (
            <a-tooltip title={text}>
              {text.length > 12 ? text.substr(0, 12) + '...' : text}
            </a-tooltip>
          )
        },
        {
          title: '检查人员',
          dataIndex: 'userName'
        },
        {
          title: '违章单位',
          dataIndex: 'organizationName',
          width: 200,
          customRender: (text) => (
            <a-tooltip title={text}>
              {text.length > 12 ? text.substr(0, 12) + '...' : text}
            </a-tooltip>
          )
        },
        {
          title: '违章人员',
          dataIndex: 'violationUserName'
        },
        {
          title: '违章性质',
          dataIndex: 'violationType'
        },
        {
          title: '作业项目',
          dataIndex: 'workItem'
        },
        {
          title: '是否重复性违章',
          dataIndex: 'timesViolation',
          width: 120,
          render: (text, record) => ((record.timesViolation && record.timesViolation === 1) ? '是' : '否')
        },
        {
          title: '违章描述',
          dataIndex: 'description',
          customRender: (text) => (
            <a-tooltip title={text}>
              {text.length > 12 ? text.substr(0, 12) + '...' : text}
            </a-tooltip>
          )
        },
        {
          title: '记分',
          dataIndex: 'score'
        },
        {
          title: '罚款',
          dataIndex: 'fine'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        return getQHSEComPage(Object.assign(parameter, this.queryParam)).then((res) => {
          res.data.rows.forEach(row => {
           if (row.timesViolation === 1) {
             row.timesViolation = '是'
           } else if (row.timesViolation === 0) {
             row.timesViolation = '否'
           } else {
             row.timesViolation = ''
           }
          })
          return res.data
        })
      },
      batchExportLoading: false,
      exportProgress: 0,
      TimeEnd: moment(new Date(), 'YYYY-MM-DD'),
      TimeOn: moment(new Date(), 'YYYY-MM-DD').subtract(1, 'months'),
      selectedKeys: [],
      selectedRows: [],
      defaultExpandedKeys: [],
      selectedCheckTypes: [],
      dangerCheckData: [],
      selectedCheckTypes1: [],
      selectedWorkType: [],
      selectedRisk: [],
      selectedPosition: [],
      selectedLocation: [],
      selectedAge: [],
      selectedEmployeeType: [],
      selectedWorkYears: [],
      selectedViolationType: [],
      selectedWorkSpecialty: [],
      score: '',
      fine: '',
      CheckTypeList: [],
      QHSEOrganizationTree: [],
      QHSEOrganizationTree1: [],
      QHSEKeyWorkSpecialtyList: [],
      KeyWorkTypeList: [],
      LocationList: [],
      PositionList: [],
      QHSEAgeList: [],
      QHSEYGXZList: [],
      QHSEGLList: [],
      enterSyslist: [],
      ViolationTypeList: [],
      previewVisible: false,
      visible: false,
      UserName: '',
      RiskList: [],
      QHSEViolationCategoryLBTree: [],
      queryParam1: {},
      simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
      replaceFields: {
        children: 'children',
        title: 'title',
        key: 'workflowId',
        value: 'id',
        parentId: 'parentId'
      }
    }
  },
  watch: {
    'fine'(newValue) {
      if (newValue === '') {
        this.queryParam.fine = 0
      } else {
        this.queryParam.fine = newValue
      }
    },
    'score'(newValue) {
      if (newValue === '') {
        this.queryParam.score = 0
      } else {
        this.queryParam.score = newValue
      }
    }
  },
  computed: {
      ...mapGetters(['userInfo'])
    },
  mounted() {
    this.addRowClass()
    window.addEventListener('resize', this.handleResize)
    this.handleResize()
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.handleResize)
  },
  created() {
    this.getDangerCheckType()
    this.getQHSEOrganizationTree()
    this.getQHSEOrganizationTree1()
    this.getQHSEKeyWorkSpecialtyList()
    this.getQHSEAgeList()
    this.getQHSEYGXZList()
    this.getQHSEGLList()
    this.getQHSEXyViolationTypeList()
    this.getQHSEViolationCategoryLBTree()
    this.getCheckTypeList()
    this.getQHSEEnterSysList()
    this.getRiskList()
    this.columns.push({
      title: '操作',
      width: '170px',
      dataIndex: 'action',
      scopedSlots: { customRender: 'action' }
    })
    const id = Vue.ls.get('id')
    if (id) {
      this.queryParam.id = id
      this.loadData()
      Vue.ls.remove('id')
    }
  },
  methods: {
    getDangerCheckType() {
          getDangerCheckType().then(res => {
            this.dangerCheckData = res.data
          })
        },
    handleChangeStatus (value) {
      if (value) {
        this.getQHSETimerTimersStart()
      } else {
        this.getQHSETimerTimersClose()
      }
    },
    getQHSETimerTimersStart() {
      getQHSETimerTimersStart()
    },
    getQHSETimerTimersClose() {
      getQHSETimerTimersClose()
    },
    handleSend (record) {
      this.queryParam1 = {
        id: record.qhseXyViolationId,
        time: record.enterTime,
        orgId: record.secondOrganizationId,
        type: record.violationType
      }
      getDataPush(this.queryParam1).then(res => {
        // console.log('res', res)
      })
    },
    chooseVioPeople(userName, userId) {
      this.UserName = userName
      this.queryParam.UserId = userId
      this.visible = false
    },
    handleCancel() {
        this.previewVisible = false
        this.visible = false
    },
    showModals() {
      this.visible = true
    },
    handleResize() {
      var myElement = this.$refs.myElement
      if (myElement) {
        var width = myElement.offsetWidth
        this.selectWidth = (width - 12 * 6) / 4 - 115
      }
    },
    addRowClass(index) {
      const rows = this.$refs.table.$el.querySelectorAll('.s-table-tbody tr')
      rows.forEach((row, index) => {
        row.classList.add(index % 2 === 0 ? 'even-row' : 'odd-row')
      })
    },
    handleClick() {
      // console.log('111', this.queryParam)
      this.queryParam.id = ''
      if ((!this.TimeOn || !this.TimeEnd) && (this.TimeOn || this.TimeEnd)) {
        this.$message.warning('请填写完整的时间信息')
      } else if ((!this.queryParam.fineSymbol || !this.queryParam.fine) && (this.queryParam.fineSymbol || this.queryParam.fine)) {
        this.$message.warning('请填写完整的罚款信息')
      } else if ((!this.queryParam.scoreSymbol || !this.queryParam.score) && (this.queryParam.scoreSymbol || this.queryParam.score)) {
        this.$message.warning('请填写完整的记分信息')
      } else {
        this.exportParam = { ...this.queryParam }
        // console.log('exportParam:', this.exportParam)
        this.$refs.table.refresh(true)
      }
    },
    onChange1(date, dateString) {
      // console.log(dateString, date)
      if (this.queryParam.TimeEnd && dateString) {
        if (dateString > this.queryParam.TimeEnd) {
          this.$message.error('开始时间不能晚于结束时间')
          this.TimeEnd = moment(new Date(), 'YYYY-MM-DD')
          this.TimeOn = moment(new Date(), 'YYYY-MM-DD').subtract(1, 'months')
          this.queryParam.TimeOn = moment(new Date()).subtract(1, 'months').format('YYYY-MM-DD')
          this.queryParam.TimeEnd = moment(new Date()).format('YYYY-MM-DD')
        } else {
          this.queryParam.TimeOn = dateString
        }
      } else {
        this.queryParam.TimeOn = dateString
      }
    },
    onChange2(date, dateString) {
      if (this.queryParam.TimeOn && dateString) {
        if (this.queryParam.TimeOn > dateString) {
          this.$message.error('开始时间不能晚于结束时间')
          this.TimeEnd = moment(new Date(), 'YYYY-MM-DD') + 'T' + moment().format('23:59:59')
          this.TimeOn = moment(new Date(), 'YYYY-MM-DD').subtract(1, 'months')
          this.queryParam.TimeOn = moment(new Date()).subtract(1, 'months').format('YYYY-MM-DD')
          this.queryParam.TimeEnd = moment(new Date()).format('YYYY-MM-DD') + 'T' + moment().format('23:59:59')
        } else {
          this.queryParam.TimeEnd = dateString + 'T' + moment().format('23:59:59')
        }
      } else {
        this.queryParam.TimeEnd = dateString + 'T' + moment().format('23:59:59')
      }
    },
    handleCheckTypeChange(value) {
      if (value.includes('全部')) {
        // 选中了全部选项，将所有选项都添加到 selectedCheckTypes 中
        this.selectedCheckTypes = this.CheckTypeList.map(item => item.item)
      }
      this.queryParam.CheckTypes = this.selectedCheckTypes.map(option => option.toString())
    },
    handleCheckTypeChange1(value) {
      if (value.includes('全部')) {
        // 选中了全部选项，将所有选项都添加到 selectedCheckTypes 中
        this.selectedCheckTypes1 = this.enterSyslist.map(item => item.item)
      }
      this.queryParam.EnterSys = this.selectedCheckTypes1.map(option => option.toString())
    },
    statusFilter (status) {
        // eslint-disable-next-line eqeqeq
        const values = this.QHSEOrgnizationTree.filter(item => item.code === status)
        if (values.length > 0) {
          return values[0].value
        }
    },
    // 组织树
    getQHSEOrganizationTree () {
      this.secondOraName.id = this.userInfo.secondOrganizationName
      getQHSEOrganizationTree(Object.assign(this.secondOraName)).then(res => {
        // console.log('tree:', res.data)
        this.treeLoading = false
        if (!res.success) {
          return
        }
        this.QHSEOrganizationTree = res.data
        if (res.data.length === 0) {
          this.secondOraName.id = '机关总部'
          getQHSEOrganizationTree(Object.assign(this.secondOraName)).then(res => {
            this.QHSEOrganizationTree = res.data
          })
        }
        })
      },
    getQHSEOrganizationTree1 () {
      this.secondOraName.id = '安检院'
      getQHSEOrganizationTree(Object.assign(this.secondOraName)).then(res => {
        // console.log('tree:', res.data)
        this.treeLoading = false
        if (!res.success) {
          return
        }
        this.QHSEOrganizationTree1 = res.data
      })
    },
    // 年龄
    getQHSEAgeList(text) {
      getQHSEAgeList().then((res) => {
        this.QHSEAgeList = res.data
      })
    },
    // 工龄
    getQHSEGLList(text) {
      getQHSEGLList().then((res) => {
        this.QHSEGLList = res.data
      })
    },
    // 用工性质
    getQHSEYGXZList(text) {
      getQHSEYGXZList().then((res) => {
        this.QHSEYGXZList = res.data
      })
    },
    // 作业专业
    getQHSEKeyWorkSpecialtyList(text) {
      getQHSEKeyWorkSpecialtyList().then((res) => {
        this.QHSEKeyWorkSpecialtyList = res.data
      })
    },
    // 违章性质
    getQHSEXyViolationTypeList(text) {
      getQHSEXyViolationTypeList().then((res) => {
        this.ViolationTypeList = res.data
      })
    },
    // 检查类型-数据来源
    getCheckTypeList(text) {
      getCheckTypeList().then((res) => {
        this.CheckTypeList = res.data
      })
    },
    // 数据录入来源
    getQHSEEnterSysList(text) {
      getQHSEEnterSysList().then((res) => {
        this.enterSyslist = res.data
       })
    },
    // 风险等级
    getRiskList(text) {
      getRiskList().then((res) => {
        this.RiskList = res.data
      })
    },
    // 违章类别
    getQHSEViolationCategoryLBTree() {
      getQHSEViolationCategoryLBTree().then((res) => {
        this.formLoading = false
        if (!res.success) {
          this.QHSEViolationCategoryLBTree = []
          return
        }
        this.QHSEViolationCategoryLBTree = res.data
      })
    },
    // 更改违章单位
    handleOrganizationSelectChange(val, opt, extra) {
      if (extra.triggerNode === undefined) {
        this.queryParam.OrganizationName = null
        this.queryParam.OrganizationId = null
      } else {
        const option = extra.triggerNode._props.title
        this.queryParam.OrganizationName = option
        this.queryParam.OrganizationId = extra.triggerNode._props.value
      }
    },
    // 更改检查单位
    onChangeCheckData(value, label, extra) {
      // console.log(value, label, extra)
      if (extra.triggerNode === undefined) {
        this.queryParam.CheckOrganizationName = null
        this.queryParam.CheckOrganizationId = null
      } else {
        this.queryParam.CheckOrganizationName = extra.triggerNode._props.title
        this.queryParam.CheckOrganizationId = extra.triggerNode._props.value
      }
    },
    // 更改作业专业
    handleZYZYSelectChange(value, option) {
      this.KeyWorkTypeList = []
      this.LocationList = []
      this.PositionList = []
      this.selectedLocation = []
      this.selectedPosition = []
      this.selectedWorkType = []
      this.queryParam.workType = []
      this.queryParam.location = []
      this.queryParam.position = []

      if (option) {
        let codes = []
        let labels = []
        if (value.includes('全部')) {
          this.selectedWorkSpecialty = this.QHSEKeyWorkSpecialtyList.map(item => item.specialty)
          codes = this.QHSEKeyWorkSpecialtyList.map(item => item.specialtyCode)
          labels = this.QHSEKeyWorkSpecialtyList.map(item => item.specialty)
        } else {
          codes = option.map(item => item.data.attrs.code)
          labels = option.map(item => item.componentOptions.propsData.value)
        }
        // console.log('option:', option)
        // console.log('codes:', codes)
        // console.log('labels:', labels)
        for (let i = 0; i < codes.length; i++) {
          const code = codes[i]
          const label = labels[i]
          getQHSEKeyWorkTypePage({ 'code': code }).then(res => {
            const rowsWithIndex = res.data.rows.map(row => {
              return {
                ...row,
                workType: `${label}-${row.workType}`
              }
            })
            this.KeyWorkTypeList = this.KeyWorkTypeList.concat(rowsWithIndex)
          })
          getQHSELocationPage({ 'code': code }).then(res => {
            const rowsWithIndex = res.data.rows.map(row => {
              return {
                ...row,
                location: `${label}-${row.location}`
              }
            })
            this.LocationList = this.LocationList.concat(rowsWithIndex)
          })
          getQHSEPositionPage({ 'code': code }).then(res => {
            const rowsWithIndex = res.data.rows.map(row => {
              return {
                ...row,
                position: `${label}-${row.position}`
              }
            })
            this.PositionList = this.PositionList.concat(rowsWithIndex)
          })
        }
      }
      this.queryParam.workSpecialty = [...this.selectedWorkSpecialty]
    },
    // 更改关键作业类型
    handleKeyWorkTypeSelectChange(value, option) {
      if (value.includes('全部')) {
        this.selectedWorkType = this.KeyWorkTypeList.map(item => item.workType)
      }
      this.queryParam.workType = [...this.selectedWorkType]
    },
    handleRiskSelectChange(value, option) {
      if (value.includes('全部')) {
        this.selectedRisk = this.RiskList.map(item => item.item)
      }
      this.queryParam.risk = [...this.selectedRisk]
    },
    handleLocationSelectChange(value, option) {
      if (value.includes('全部')) {
        this.selectedLocation = this.LocationList.map(item => item.location)
      }
      this.queryParam.location = [...this.selectedLocation]
    },
    handlePositionSelectChange(value, option) {
      if (value.includes('全部')) {
        this.selectedPosition = this.PositionList.map(item => item.position)
      }
      this.queryParam.position = [...this.selectedPosition]
      // this.queryParam.position = value
      // this.queryParam = Object.assign({}, this.queryParam, option.context.queryParam)
    },
    handleAgeChange(value, option) {
      if (value.includes('全部')) {
        this.selectedAge = this.QHSEAgeList.map(item => item.item)
      }
      this.queryParam.age = [...this.selectedAge]
    },
    handleEmployeeTypeSelectChange(value, option) {
      if (value.includes('全部')) {
        this.selectedEmployeeType = this.QHSEYGXZList.map(item => item.item)
      }
      this.queryParam.employeeType = [...this.selectedEmployeeType]
    },
    handleWorkYearsSelectChange(value, option) {
      if (value.includes('全部')) {
        this.selectedWorkYears = this.QHSEGLList.map(item => item.item)
      }
      this.queryParam.workYears = [...this.selectedWorkYears]
    },
    handlViolationTypeSelectChange(value, option) {
      if (value.includes('全部')) {
        this.selectedViolationType = this.ViolationTypeList.map(item => item.violationType)
      }
      this.queryParam.violationType = [...this.selectedViolationType]
    },
    handleViolationCategorySelectChange(val, opt, extra) {
      if (extra.triggerNode === undefined) {
        this.queryParam.violationCategory = null
      } else {
        const option = extra.triggerNode._props.title
        this.queryParam.violationCategory = option
      }
    },
    handleOk() {
      this.$refs.table.refresh()
    },
    handleExport(parameter) {
      this.batchExportLoading = true
      this.exportProgress = 0 // 重置进度
      this.exportParam = { ...this.queryParam }

      const interval = setInterval(() => {
        if (this.exportProgress < 90) { // 进度最高到 90%，剩下的 10% 在下载完成时更新
          this.exportProgress += 10
        }
      }, 500)
      getDownloadExcel(Object.assign(parameter, this.exportParam))
        .then(response => {
          clearInterval(interval) // 清除定时器
          this.exportProgress = 100 // 导出完成后，设置进度为 100%
          // 创建下载链接
          const downloadLink = document.createElement('a')
          downloadLink.href = window.URL.createObjectURL(response.data)
          // 设置下载链接的属性
          downloadLink.download = '违章_' + new Date().toISOString() + '.xlsx'
          downloadLink.target = '_blank'
          // 在下载链接的 click 事件处理程序中停止加载状态
          downloadLink.addEventListener('click', () => {
            this.batchExportLoading = false
          })
          // 触发下载
          downloadLink.click()
        })
        .catch(error => {
          clearInterval(interval) // 清除定时器
          console.error('下载失败:', error)
          this.batchExportLoading = false
        })
    },
    reset() {
      this.queryParam = {
        TimeOn: moment(new Date()).subtract(1, 'months').format('YYYY-MM-DD'),
        TimeEnd: moment(new Date()).format('YYYY-MM-DD')
      }
      this.TimeEnd = moment(new Date(), 'YYYY-MM-DD')
      this.TimeOn = moment(new Date(), 'YYYY-MM-DD').subtract(1, 'months')
      this.selectedCheckTypes = []
      this.selectedCheckTypes1 = []
      this.selectedWorkType = []
      this.selectedRisk = []
      this.selectedPosition = []
      this.selectedLocation = []
      this.selectedAge = []
      this.selectedEmployeeType = []
      this.selectedWorkYears = []
      this.selectedViolationType = []
      this.selectedWorkSpecialty = []
      this.score = ''
      this.fine = ''
      this.exportParam = {}
      this.LocationList = []
      this.PositionList = []
      this.KeyWorkTypeList = []
    }
  }
}
</script>
<style lang="less" scoped>
/deep/.ant-table-tbody tr:nth-child(2n) {
  background-color:#f5f5f5;
}
.table-operator {
  margin-bottom: 18px;
}
.my-dropdown .ant-select-item {
  max-height: 200px;
  overflow-y: auto;
}
button {
  margin-right: 8px;
}
.search-row {
  display: flex;
  align-items: center;
}

.search-buttons {
  display: flex;
  justify-content: flex-end;
}
.ant-form-item-label {
  width: 800px; /* 将标签宽度改为 100 像素 */
}
.smallSelect {
  width: 40%;
}
.midSelect {
  width: 60%;
}
</style>
